<?php
namespace App\controllers;
// application/controllers/BaseController.php

class BaseController extends \Yaf\Controller_Abstract
{
    public function init()
    {
        // 禁止视图渲染
        \Yaf\Dispatcher::getInstance()->autoRender(false);
    }

    protected function respond($data)
    {
        // 构造正常响应格式
        $response = [
            'code' => 0,
            'data' => $data,
        ];

        // 将响应转换为 JSON 格式
        $jsonResponse = json_encode($response);

        // 发送 JSON 响应
        $this->getResponse()->setHeader('Content-Type', 'application/json');
        $this->getResponse()->setBody($jsonResponse);
        return true;
    }
}
